package com.itheima.common;

/**
 * @Author: lcc
 * @Desc: 基于ThreadLocal封装工具类，用户保存和获取当前登录用户id
 * @Date: 2022/6/5 21:48
 */
public class BaseContext {
    private static ThreadLocal<Long> threadLocal_employee = new ThreadLocal<>();
    private static ThreadLocal<Long> threadLocal_user = new ThreadLocal<>();
    /**
     * 设置值
     * @param id
     */
    public static void setCurrentId(Long id){
        threadLocal_employee.set(id);
    }
    public static void setUserId(Long id){
        threadLocal_user.set(id);
    }
    /**
     * 获取值
     * @return
     */
    public static Long getCurrentId(){
        return threadLocal_employee.get();
    }
    public static Long getUserId(){
        return threadLocal_user.get();
    }
    /**
     * 清理值--如果使用的是线程池，注意要不上一个请求的线程中的数据清理掉
     * @return
     */
    public static void clearCurrentId(){
        threadLocal_employee.remove();
    }
    public static void clearUserId(){
        threadLocal_user.remove();
    }
}
